package com.dependencies.springsession.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author zhizhou   2024/7/24 23:17
 */
@RestController
@RequestMapping("/session")
public class SessionController {
    
    @GetMapping("/create")
    public String createSession(HttpSession session) {
        String sessionId = UUID.randomUUID().toString();
        session.setAttribute("sessionId", sessionId);
        return "创建会话Session ID: " + sessionId;
    }
    
    @GetMapping("/get")
    public String getSession(HttpSession session) {
        String sessionId = (String) session.getAttribute("sessionId");
        return "获取会话 Session ID: " + sessionId;
    }
    
}
